<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>SSE 实时推送时间</title>
</head>
<body>
<h1>实时推送当前时间</h1>
<ul id="time-list"></ul>

<script>
    const eventSource = new EventSource('/stream/time');

    eventSource.onmessage = function(event) {
        const timeList = document.getElementById('time-list');
        const listItem = document.createElement('li');
        listItem.textContent = event.data;
        timeList.appendChild(listItem);
    };

    eventSource.onerror = function(error) {
        console.error('Error:', error);
        eventSource.close();
    };
</script>
</body>
</html>